<html>
  <head>
    <title>Cardinal Splines</title>
    <script type="text/javascript" src="../../protovis.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

var t = 0, dt = 0.05;

var data = pv.range(10).map(function(x) {
        return {x: x, y: Math.sin(x * Math.PI + Math.PI / 2)};
      }),
    w = 800,
    h = 400,
    x = pv.Scale.linear(data, function(d) d.x).range(0, w),
    y = pv.Scale.linear(-1.5, 1.5).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .strokeStyle("#ccc")
    .margin(20);

vis.add(pv.Rule)
    .data(y.ticks())
    .visible(function() !(this.index % 2))
    .bottom(y)
    .strokeStyle("#eee")
  .anchor("left").add(pv.Label)
    .text(function(d) d.toFixed(1));

vis.add(pv.Rule)
    .data(x.ticks())
    .visible(function(d) d > 0)
    .left(x)
    .strokeStyle("#eee")
  .anchor("bottom").add(pv.Label)
    .text(function(d) d.toFixed());

vis.add(pv.Line)
    .data(data)
    .left(function(d) x(d.x))
    .bottom(function(d) y(d.y))
    .interpolate("cardinal")
    .tension(function() t);

vis.render();

setInterval(function() {
  t += dt;
  if (t < -1) { t = -1; dt *= -1; }
  else if (t > 2) { t = 2; dt *= -1; }
  vis.render();
}, 42);

    </script>
  </body>
</html>
